package com.zone.vehicle.superApps.view.home.app.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.zone.sdk.module.comment.entity.CommentEntity;
import com.zone.vehicle.lib.view.star.Star;
import com.zone.vehicle.superApps.R;
import com.zone.vehicle.superApps.view.home.app.detail.widget.VerticalCommentLayout;

/**
 * @author ganhuanhui
 * 时间：2019/12/19 0019
 * 描述：
 */
public class CommentDialogSingleAdapter extends BaseQuickAdapter<CommentEntity, BaseViewHolder> {

    private VerticalCommentLayout.CommentItemClickListener mItemClickListener;

    public CommentDialogSingleAdapter(VerticalCommentLayout.CommentItemClickListener mItemClickListener) {
        super(R.layout.item_comment_new);
        this.mItemClickListener = mItemClickListener;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, CommentEntity content) {

//            LinearLayout ll_like = helper.getView(R.id.ll_like);
//            RelativeLayout rl_group = helper.getView(R.id.rl_group);

        RoundedImageView iv_header = helper.getView(R.id.iv_header);
        ImageView isPraise = helper.getView(R.id.isPraise);
        TextView tv_like_count = helper.getView(R.id.tv_like_count);
        TextView tv_user_name = helper.getView(R.id.tv_user_name);
        TextView tv_content = helper.getView(R.id.tv_content);
        TextView tv_time = helper.getView(R.id.tv_time);
        TextView modelAbbreviation = helper.getView(R.id.modelAbbreviation);
        TextView replyCount = helper.getView(R.id.replyCount);
        Star star = helper.getView(R.id.score);

        helper.addOnClickListener(R.id.rl_group);
//        helper.addOnClickListener(R.id.ll_like);
        Glide.with(mContext).load(content.getPublisher().getHeadPortraitUrl()).into(iv_header);
//        star.setMark((float) (Integer.parseInt(content.getScore()) / 5));
        star.setMark(3f);

        isPraise.setImageResource(content.getIsPraise() == 0 ? R.mipmap.icon_topic_post_item_like : R.mipmap.icon_topic_post_item_like_blue);
        tv_like_count.setText(String.valueOf(content.getPraiseCount()));

        tv_content.setText(content.getContent());
        tv_user_name.setText(content.getPublisher().getNickName());
//        String time = TimeUtils.getRecentTimeSpanByNow(Long.valueOf(content.getCreateTime()));
        tv_time.setText(content.getCreateTime());
        modelAbbreviation.setText(content.getModelAbbreviation());
        replyCount.setText(String.valueOf(content.getReplyCount()));

        if (content.getReplyCount() > 0) {
            VerticalCommentLayout commentWidget = helper.getView(R.id.verticalCommentLayout);
            commentWidget.setVisibility(View.VISIBLE);
            int size = content.getReplyCount();
            commentWidget.setTotalCount(size + 10);
            commentWidget.setPosition(helper.getAdapterPosition());
            commentWidget.setOnCommentItemClickListener(mItemClickListener);
            int limit = helper.getAdapterPosition() + 1;
            commentWidget.addCommentsWithLimit(content.getReplyList(), size, false);
//                rl_group.setTag(commentWidget);
        }

    }
}
